/*
 * @Descripttion: 
 * @version: 请写项目版本
 * @Author: @cdm
 * @Date: 2021-10-14 09:25:19
 * @LastEditors: @cdm
 * @LastEditTime: 2021-12-20 14:12:37
 * No pains no gains
 */
// Learn TypeScript:
//  - https://docs.cocos.com/creator/manual/en/scripting/typescript.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html

import { achieveType } from "../../../../script/game/gameType";
import { ListViewAdapter } from "../../../../script/util/ListView/ListViewAdapter";
import { ccs } from "../../../../script/util/services";
import { TouchExtend } from "../../../../script/util/TouchExd";
import { touchExd } from "../../../../script/util/TouchExtend";
import { WinBase } from "../../../../script/wins/WinBase";
import achieve from "../tabShow/achieve";
import achieveItem from "./achieveItem";

const {ccclass, property} = cc._decorator;

@ccclass
export default class NewClass extends WinBase {

    achieveList = ccs.dataMgr.getAchieveList();
    
    @property(ListViewAdapter)
    list: ListViewAdapter = null;

    myList = [];

    @property(cc.Prefab)
    treePre: cc.Prefab = null;

    treeNode = null;
    start () {
        this.treeNode = cc.instantiate(this.treePre);
        this.nodes.tree.addChild(this.treeNode);
        this.updateTree();
        // 显示成就列表
        this.list.updateItems(this.achieveList);

        this.touchEndEventScale(this.nodes.finish, () => {
            if(this.myList.length < 10) {
                ccs.winMgr.showWin("toast", {msg: "没有梦想的咸鱼，人生至少要十个梦想吧"})
                return ;
            }
            ccs.winMgr.showWin("mainWin");
        })
        this.touchEndEventScale(this.nodes.restart, () => {
            this.myList = [];
            this.updateTree();

            this.achieveList = ccs.dataMgr.getAchieveList();
            this.list.updateItems(this.achieveList);
            ccs.winMgr.showWin("toast", {msg: "人生没有重来的机会，好好珍惜"});
        })
    }
    updateTree() {
        this.treeNode.children[1].getComponent(achieve).setAchieveList(this.myList);
    }
    onCell(node: cc.Node, data: achieveType, idx: number) {
        TouchExtend.touchEndScale(node, () => {
            cc.log(data);
            this.myList.push(data);
            this.achieveList.splice(idx, 1);
            this.list.updateItems(this.achieveList);
            this.updateTree();
        })
    }
}
